package com.guan.ordering_sys.generator.controller;


import com.guan.ordering_sys.common.ResultApi;
import com.guan.ordering_sys.generator.entity.GoodsParameter;
import com.guan.ordering_sys.generator.service.GoodsParameterService;
import com.guan.ordering_sys.param.GoodsParameterAddParam;
import com.guan.ordering_sys.param.GoodsParameterUpdateParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 关远键
 * @version v1.0.2
 * @since 2021-06-18
 */
@Api(tags = "商品参数控制器")
@RestController
@RequestMapping("/api/goods-parameter")
public class GoodsParameterController {

    @Autowired
    private GoodsParameterService parameterService;

    @ApiOperation("添加")
    @PostMapping("/add")
    public ResultApi add(@RequestBody GoodsParameterAddParam param) {
        Long id = parameterService.add(param);
        return ResultApi.success(id);
    }


    @ApiOperation("修改")
    @PutMapping("/updateById")
    public ResultApi updateById(@RequestBody GoodsParameterUpdateParam param) {
        int i = parameterService.updateById(param);
        return ResultApi.success(i);
    }

    @ApiOperation("删除")
    @DeleteMapping("/deleteById")
    public ResultApi deleteById(Long id) {
        int i = parameterService.deleteById(id);
        return ResultApi.success(i);
    }

    @ApiOperation("查询")
    @GetMapping("/query/{id}")
    public ResultApi query(@PathVariable("id") Long id) {
        List<GoodsParameter> list = parameterService.query(id);
        return ResultApi.success(list);
    }

}

